package com.animee.day11.utils;

import ohos.aafwk.ability.AbilitySlice;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.PageSliderProvider;

import java.util.List;

public class ImageSliderProvider extends PageSliderProvider{
    AbilitySlice context;
    List<Component>mDatas;
    public ImageSliderProvider(AbilitySlice context, List<Component> mDatas) {
        this.context = context;
        this.mDatas = mDatas;
    }
    @Override  //返回能够滑动几页
    public int getCount() {return mDatas.size();}
    @Override   //根据指定位置创建页，放入容器里
    public Object createPageInContainer(ComponentContainer componentContainer, int i) {
        Component component = mDatas.get(i);
        componentContainer.addComponent(component);
        return component;
    }
    @Override   //销毁指定位置的页面
    public void destroyPageFromContainer(ComponentContainer componentContainer, int i, Object o) {
        Component component = mDatas.get(i);
        componentContainer.removeComponent(component);
    }
    @Override
    public boolean isPageMatchToObject(Component component, Object o) {
        return component == o;
    }
}